package com.study_security.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.study_security.dto.ProjectDTO;
import com.study_security.dto.ProjectFormDTO;
import com.study_security.entity.Project;
import com.study_security.mapper.ProjectMapper;
import com.study_security.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    @Override
    public List<Project> getOngoingProjects(Long userId) {
        return projectMapper.selectOngoingProjects(userId);
    }

    @Override
    public List<Project> getCompletedProjects(Long userId) {
        return projectMapper.selectCompletedProjects(userId);
    }

    @Override
    public List<Project> getAllProject() {
        return projectMapper.getAllProject();
    }

    @Override
    public List<Project> searchOngoingProjects(Long userId,String keyword) {
        return projectMapper.searchOngoingProjects(userId,keyword);
    }

    @Override
    public List<Project> searchCompletedProjects(Long userId,String keyword) {
        return projectMapper.searchCompletedProjects(userId,keyword);
    }

    @Override
    public boolean addProject(Long userId,Project project) {
        return projectMapper.insert(project) > 0;
    }

    @Override
    public boolean projectNameExists(String projectName) {
        return projectMapper.countByProjectName(projectName) > 0;
    }
    @Override
    public List<ProjectDTO> getUserProjects(Long userId) {
        return projectMapper.selectUserProjects(userId);
    }

    @Override
    public Project getProjectById(Long projectId) {
        return projectMapper.selectProjectById(projectId);
    }

    @Override
    public List<Project> getAllProjects() {
        return projectMapper.selectAllProject();
    }

    @Override
    public List<ProjectFormDTO> getAllProjectFormDTOByUserId(Long userId) {
        return projectMapper.selectAllProjectFormDTOByUserId(userId);
    }

    @Override
    public List<Project> getAllProjectByUserId(Long userId) {
        return projectMapper.selectAllProjectByUserId(userId);
    }

    @Override
    public List<ProjectFormDTO> getAllProjectFormDTO() {
        return projectMapper.selectAllProjectFormDTO();
    }
}
